<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <img id="h1" src="C:\Users\justdoit\Desktop\HTML\快速入门\kk.jpg"><br><br>
    <div class="cls">康康</div><br>
    <div class="cls">南昌</div><br>
    <input type="checkbox" name="hobby">电影
    <input type="checkbox" name="hobby">旅游
    <input type="checkbox" name="hobby">游戏
    
</body>
<script>
    //获取Element元素
    //1.根据id获取
   //var img = document.getElementById('h1');
   //alert(img);
   //2.根据标签获取-div
   //var divs = document.getElementsByTagName('div');
   //for(let i = 0;i<divs.length;i++){
   // alert(divs[i]);
   //}
   //3.根据name属性获取
  // var ins = document.getElementsByName('hobby');
   //for(let i = 0;i<ins.length;i++){
//alert(ins[i]);
   //}
   //4.根据class属性获取
   //var arr = document.getElementsByClassName('cls');
   //for(let i = 0;i<arr.length;i++){
   // alert(arr[i]);
  // }
   //2.查询参考手册，属性，方法
   var arr = document.getElementsByClassName('cls');
   var div1 = arr[0];
   //改变元素内容
   div1.innerHTML="康康666"
   //让所有复选框呈选中状态
   var ins = document.getElementsByName('hobby');
   for(let i = 0;i<ins.length;i++){
    const check = ins[i];
    check.checked = true;//选中
   }



</script>
</html>